/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jogopoo.Interface;

import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *Classe da Janela de Input o Nome do jogador
 * @author pererabass
 */
public class RankingIJ extends JFrame implements ActionListener {

    public RankingIJ(int score) {
        this.setBounds(150, 250, 200, 100);
        this.setTitle("Space Invaders - Ranking");
        this.setResizable(false);
        Container contentPane = this.getContentPane();
         restricao = new GridBagConstraints();
        rkg = new Ranking();
        rkg.setVisible(true);
        this.score = score;
        
        RankingIJPanel rkgPanel = new RankingIJPanel();
        contentPane.add(rkgPanel);
        botao.addActionListener(this);
        restricao.gridy = 3;
        rkgPanel.add(botao,restricao);
        restricao.gridy = 2;

    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == botao) {

            rkg.setNome(textFild.getText());
            rkg.setScore(score);
            if(rkg.verifica(score))
            try {
                rkg.atualiza();
            } catch (IOException ex) {
                Logger.getLogger(RankingIJ.class.getName()).log(Level.SEVERE, null, ex);
            }
            this.dispose();
        }

    }

    public class RankingIJPanel extends JPanel {

        public RankingIJPanel() {
            this.setLayout(new GridBagLayout());
            this.add(new JLabel("Score: "+Integer.toString(score)), restricao);
            textFild = new JTextField("Nome", 10);
            botao = new JButton("Ok");
            restricao.gridy = 3;
            if(rkg.verifica(score))
            this.add(textFild, restricao);
        }
    }

    private JTextField textFild;
    private JButton botao;
    private Ranking rkg;
    private GridBagConstraints restricao;
    private int score;
}
